﻿#include "coleditappdialog.h"
#include "ui_coleditappdialog.h"
#include <QSqlQuery>

int COLeditappDialog::D;
COLeditappDialog::COLeditappDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::COLeditappDialog)
{
    ui->setupUi(this);
    ui->frame->resize(this->geometry().width(), ui->frame->height());
    ui->status->setText("修改信息状态：");
    connect(ui->cancelbtn,SIGNAL(clicked(bool)),this,SLOT(close()));
}

COLeditappDialog::~COLeditappDialog()
{
    delete ui;}


void COLeditappDialog::receivestr(QStringList str)
{D=str.at(0).toInt();
QDate date1=QDate::fromString(str.at(2),"yyyy-MM-dd");
QDate date2=QDate::fromString(str.at(3),"yyyy-MM-dd");
QDate date3=QDate::fromString(str.at(9),"yyyy-MM-dd");
QDate date4=QDate::fromString(str.at(12),"yyyy-MM-dd");
QDate date5=QDate::fromString(str.at(15),"yyyy-MM-dd");
ui->lenddate->setDate(date1);
ui->returndate->setDate(date2);
ui->lendway->setText(str.at(1));
ui->inquerydate->setDate(date3);
ui->officedate->setDate(date4);
ui->unitdate->setDate(date5);
ui->recordman->setText(str.at(4));
ui->others->setText(str.at(5));
ui->reason->setText(str.at(6));
ui->content->setText(str.at(7));
ui->inquerylead->setText(str.at(8));
ui->inqueryopinion->setText(str.at(10));
ui->officelead->setText(str.at(11));
ui->officeopinion->setText(str.at(13));
ui->unitlead->setText(str.at(14));
ui->unitopinion->setText(str.at(16));
}

void COLeditappDialog::on_ackbtn_clicked()
{
    if(ui->lendway->text().isEmpty()||ui->unitlead->text().isEmpty()||ui->officelead->text().isEmpty()||ui->inquerylead->text().isEmpty()||ui->content->text().isEmpty()||ui->reason->text().isEmpty()){
        ui->status->setText("修改信息状态:预计阅档和退还日期，阅档方式,阅档事由，阅档内容，各单位科室审批领导及日期不能为空！");}
    else {
    QSqlQuery query;
    query.prepare("update Approval set lendway=?,lenddate=?,returndate=?,recordman=?,reason=?,content=?,inquerylead=?,inquerydate=?,inqueryopinion=?,manageofficelead=?,manageofficedate=?,manageofficeopinion=?,manageunitlead=?,manageunitdate=?,manageunitopinion=?,others=? where ApprovalID = ?");
    query.addBindValue(ui->lendway->text());
    query.addBindValue(ui->lenddate->text());
    query.addBindValue(ui->returndate->text());
    query.addBindValue(ui->recordman->text());
    query.addBindValue(ui->reason->text());
    query.addBindValue(ui->content->text());
    query.addBindValue(ui->inquerylead->text());
    query.addBindValue(ui->inquerydate->text());
    query.addBindValue(ui->inqueryopinion->text());
    query.addBindValue(ui->officelead->text());
    query.addBindValue(ui->officedate->text());
    query.addBindValue(ui->officeopinion->text());
    query.addBindValue(ui->unitlead->text());
    query.addBindValue(ui->unitdate->text());
    query.addBindValue(ui->unitopinion->text());
    query.addBindValue(ui->others->text());
    query.addBindValue(D);
    bool ok=query.exec();
    if(ok)
    {ui->status->setText("修改信息状态:修改成功");
    this->close();}
    else
    {ui->status->setText("修改信息状态:修改失败");}
}
}
